Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@radix-ui/react-radio-group

Package Overview
Dependencies
Maintainers
6
Versions
214
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@radix-ui/react-radio-group

  • 1.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
832K
decreased by-45.18%
Maintainers
6
Weekly downloads
 
Created

What is @radix-ui/react-radio-group?

@radix-ui/react-radio-group is a React component library that provides accessible and customizable radio group components. It is part of the Radix UI suite, which focuses on providing unstyled, accessible components that can be easily styled to fit any design system.

What are @radix-ui/react-radio-group's main functionalities?

Basic Radio Group

This code demonstrates a basic radio group with three options. The `defaultValue` prop sets the initially selected option.

```jsx
import * as RadioGroup from '@radix-ui/react-radio-group';

function App() {
  return (
    <RadioGroup.Root defaultValue="option1">
      <RadioGroup.Item value="option1">Option 1</RadioGroup.Item>
      <RadioGroup.Item value="option2">Option 2</RadioGroup.Item>
      <RadioGroup.Item value="option3">Option 3</RadioGroup.Item>
    </RadioGroup.Root>
  );
}

export default App;
```

Custom Styling

This example shows how to apply custom styles to the radio group and its items using CSS classes.

```jsx
import * as RadioGroup from '@radix-ui/react-radio-group';
import './styles.css';

function App() {
  return (
    <RadioGroup.Root className="custom-radio-group" defaultValue="option1">
      <RadioGroup.Item className="custom-radio-item" value="option1">Option 1</RadioGroup.Item>
      <RadioGroup.Item className="custom-radio-item" value="option2">Option 2</RadioGroup.Item>
      <RadioGroup.Item className="custom-radio-item" value="option3">Option 3</RadioGroup.Item>
    </RadioGroup.Root>
  );
}

export default App;
```

Controlled Radio Group

This code demonstrates a controlled radio group where the selected value is managed by React state.

```jsx
import * as RadioGroup from '@radix-ui/react-radio-group';
import { useState } from 'react';

function App() {
  const [value, setValue] = useState('option1');

  return (
    <RadioGroup.Root value={value} onValueChange={setValue}>
      <RadioGroup.Item value="option1">Option 1</RadioGroup.Item>
      <RadioGroup.Item value="option2">Option 2</RadioGroup.Item>
      <RadioGroup.Item value="option3">Option 3</RadioGroup.Item>
    </RadioGroup.Root>
  );
}

export default App;
```

Other packages similar to @radix-ui/react-radio-group

FAQs

Package last updated on 13 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc